package com.claimSettlement.service.impl;

import com.claimSettlement.mapper.MenuMapper;
import com.claimSettlement.pojo.SysJurisdiction;
import com.claimSettlement.service.MenuService;
import com.claimSettlement.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 *菜单Service层接口
 *宁杰
 */
@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    MenuMapper menuMapper;
    @Autowired
    RedisTemplate redisTemplate;
    public List<SysJurisdiction> getMenuAll(int uid) {
        List<SysJurisdiction> list=null;
        if(redisTemplate.hasKey("menulist"+uid)){
            list=redisTemplate.opsForHash().values("menulist"+uid);
            return list;
        }
        list=menuMapper.getMenuAll(uid);
        Map<String,String> map=new HashMap<String, String>();
        for(SysJurisdiction sysJurisdiction:list){
            map.put(sysJurisdiction.getJno()+"", JsonUtils.objectToJson(sysJurisdiction));
        }
        redisTemplate.opsForHash().putAll("menulist"+uid,map);
        return list;
    }

    public List<String> getMenuButton(int uid,int jpid) {
        return menuMapper.getMenuButton(uid,jpid);
    }
}
